const BASE_URL = 'https://www.filecashchain.io'
function _baseMixins(base) {
    return function (api) {
        return function (api2) {
            return base + api + api2
        }
    }
}

const usersMixins = _baseMixins(BASE_URL)('/users')
const baseMixins = _baseMixins(BASE_URL)('')

module.exports = class API {
    static async sendCode(params) {
        const res = await _post(baseMixins('/sendCaptcha'), params)
        alert(res)
    }
    static async getGeetest() {
        try {
            const res = await _get(baseMixins(`/v1/validate/registerGeetest?t=${Date.now()}`))
            alert(res)
        } catch (e) {
            alert(e)
        }
    }
}

function _post(api, data = {}, method = 'POST') {
    const options = {
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json'
        },
        method: method,
        body: JSON.stringify(data)
    }
    return fetch(api, options)
}

function _get(api) {
    return fetch(api)
}
